package cn.stylefeng.guns.sys.modular.system.quartz.task;

import cn.stylefeng.guns.sys.modular.system.entity.BtyBrand;
import cn.stylefeng.guns.sys.modular.system.entity.BtyTxl;
import cn.stylefeng.guns.sys.modular.system.service.BtyBrandService;
import cn.stylefeng.guns.sys.modular.system.service.BtyTxlService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class cwmDataJob {

    @Resource
    private BtyBrandService btyBrandService;

    @Resource
    private BtyTxlService btyTxlService;

    @XxlJob("cwmDataJob")
    public void updateCwmAll() {
        try {
            log.info("-----------------财务码维护同步营业日定时器开始-----------------");
            List<Map<String, Object>> listCwmAll;
            listCwmAll = this.btyBrandService.listCwmAll();
            if (listCwmAll.size() != 0) {
                listCwmAll.forEach(i -> {
                    BtyBrand btyBrand = new BtyBrand();
                    btyBrand.setId(Long.valueOf(String.valueOf(i.get("id"))));
                    btyBrand.setKyrq(i.get("kyrq").toString());
                    btyBrandService.updateById(btyBrand);
                });
            }
            listCwmAll.clear();
            listCwmAll = this.btyTxlService.listCwmAll();
            if (listCwmAll.size() != 0) {
                listCwmAll.forEach(i -> {
                    BtyTxl btyTxl = new BtyTxl();
                    btyTxl.setId(Long.valueOf(String.valueOf(i.get("id"))));
                    btyTxl.setKysj(i.get("kyrq").toString());
                    btyTxlService.updateById(btyTxl);
                });
            }
            log.info("-----------------财务码维护同步营业日定时器结束-----------------");
        } catch (Exception e) {
            log.info("财务码维护同步营业日定时器同步数据失败：{}", e.getMessage());
            e.printStackTrace();
        }
    }
}
